package com.yuanqi.Controller;

import com.yuanqi.Common.Pojo.Dto.TopicDto;
import com.yuanqi.Common.Pojo.Vo.PostDetail;
import com.yuanqi.Common.Pojo.Vo.PostVo;
import com.yuanqi.Common.Pojo.Vo.TopicVo;
import com.yuanqi.Common.Pojo.entity.TopicClass;
import com.yuanqi.Return.Result;
import com.yuanqi.Service.TopicService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping("/v1/topic")
@CrossOrigin
public class TopicController {
    @Resource
    TopicService topicService;

    @GetMapping("/getList")
    public Result getList() {
        List<TopicClass> list = topicService.getlist();
        return Result.success(list);
    }

    /**
     * 获取热门话题
     *
     * @param current
     * @return
     */
    @GetMapping("/getHotTopic")
    public Result getTopic(Integer current) throws ParseException {
        List<TopicVo> list = topicService.getHotTopic(current);
        return Result.success(list);
    }

    /**
     * 根据话题分类获取话题
     * @param current
     * @param classId
     * @return
     */
    @GetMapping("/getTopicByClassId")
    public Result getTopicByClassId(Integer current,Integer classId) throws ParseException, InterruptedException {
        List<TopicVo> list = topicService.getTopicByClassId(current,classId);
        return Result.success(list);
    }

    /**
     * 获取话题下的文章
     *
     * @param id
     * @param current
     * @return
     */
    @GetMapping("/getPostList")
    public Result getPostList( Integer id, Integer current,Boolean isTime,Long userId) throws InterruptedException {
        List<PostVo> postVos = topicService.getpostList(id, current, isTime,userId);
        return Result.success(postVos);
    }

    @PostMapping("/SearchTopic")
    public Result SearchTopic(@RequestBody TopicDto topicDto) throws ParseException, InterruptedException {
        List<TopicVo> list = topicService.SearchTopic(topicDto);
        return Result.success(list);
    }
}
